package com.lyj.ssm.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Created by yujin.liu on 2018/7/12.
 */
@Configuration
@EnableSwagger2
@EnableWebMvc
public class SwaggerConfig {

    @Bean
    public Docket testApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("测试接口").forCodeGeneration(true).select().apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.regex("/api/test/.*"))
                .build().apiInfo(apiInfo());
    }

    @Bean
    public Docket messageApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("消息接口").forCodeGeneration(true).select().apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.regex("/api/message/.*"))
                .build().apiInfo(apiInfo());
    }

    private ApiInfo apiInfo() {
        Contact contact = new Contact("lyj","www.lyj.com","yujin1liu@163.com");
        ApiInfo apiInfo = new ApiInfoBuilder().license("Apache License Version 2.0").title("ssm demo").description("ssm demo").contact(contact).version("1.0").build();
        return apiInfo;
    }


}
